<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"         
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:p="http://primefaces.org/ui">

    <h:body>

        <ui:composition template="./../templates/templateNECS.xhtml">

            <ui:define name="top">
                Criar uma nova encomenda
            </ui:define>
            
            <ui:define name="left">
                <h:outputLink value="admin_encomenda_criar.xhtml">Criar Encomenda</h:outputLink>
                <br></br>
                <h:outputLink value="admin_encomenda_listar.xhtml">Lista de Encomendas</h:outputLink>
                <br></br>
                <h:outputLink value="admin_produto_catalogo_listar.xhtml">Lista de Produtos Catálogo</h:outputLink>
                <br></br>
                <h:outputLink value="admin_produtos_fisicos_listar.xhtml">Lista de Produtos Físicos</h:outputLink>
                <br></br>

            </ui:define>

            <ui:define name="content">
                <h:form>                  
                    <h:panelGrid columns="1">

                        <h:outputLabel for="ID" value="ID Encomenda: " />
                        <h:inputText
                            id="id"
                            size="20"
                            required="true"
                            requiredMessage="Erro: Deve inserir um id da encomenda."
                            value="#{administradorManager.encomendaNova.id}" >  
                        </h:inputText>   
                        <h:message for="data" errorStyle="color: red" />

                        <h:outputLabel for="data" value="Data: " />
                        <h:inputText
                            id="data"
                            size="20"
                            required="true"
                            requiredMessage="Erro: Deve inserir um Data."
                            value="#{administradorManager.encomendaNova.dataEncomenda}">
                         </h:inputText>
                        <h:message for="data" errorStyle="color: red" />
                        <h:inputText
                            id="codFarmacia"
                            size="20"
                            required="true"
                            requiredMessage="Erro: Deve inserir um Data."
                            value="#{administradorManager.encomendaNova.codFarmacia}">
                         </h:inputText>
                        <h:message for="codFarmacia" errorStyle="color: red" />
                      
                        <h:dataTable var="linhaEncomenda"
                                 summary="Tabela de linhas de venda"
                                 value="#{administradorManager.encomendaNova.listaLinhasEncomenda}"
                                 rules="all"
                                 cellpadding="5">
                            <f:facet name="header">
                                <h:outputText value="Produtos" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:outputText value="&#160;" />
                                <h:button value="+" outcome="admin_encomenda_produto_adicionar.xhtml" />  
                            </f:facet>
                            <h:column>
                                <f:facet name="header">
                                    <h:outputText value="Referência" />
                                </f:facet>
                                <h:outputText value="#{linhaVenda.produtoCatalogo.referencia}" />
                            </h:column>
                            <h:column>
                                <f:facet name="header">
                                    <h:outputText value="Nome do produto" />
                                </f:facet>
                                <h:outputText value="#{linhaVenda.produtoCatalogo.nome}" />
                            </h:column>
                            <h:column>
                                <f:facet name="header">
                                    <h:outputText value="Quantidade" />
                                </f:facet>
                                <h:outputText value="#{linhaVenda.quantidade}" />
                            </h:column>   
                            <h:column>
                                <p:commandButton onclick="PF('quantityDialog').show()" title="Alterar" value="Alterar"  >
                                    <f:setPropertyActionListener target="#{administradorManager.linhaEncomendaAtual}" value="#{linhaEncomenda}" />
                                </p:commandButton>
                            </h:column>
                        </h:dataTable> 
                        <h:commandButton
                            id="submit"
                            binding="#{administradorManager.componente}"
                            value="Criar"
                            action="#{administradorManager.criarEncomenda}" />
                        <h:message for="submit" style="color: red"/>                        
                    </h:panelGrid >
                </h:form>
                <p:dialog header="Quantidade" widgetVar="quantityDialog" modal="true" showEffect="fade" hideEffect="fade" resizable="false">
                    <h:form>
                        <p:outputPanel id="quantidadePanel" style="text-align:center;">
                            <p:panelGrid  columns="1">
                                <h:outputText value="Quantidade:" />
                                <h:inputText
                                    id="quantidade"
                                    size="12"
                                    required="true"
                                    requiredMessage="Erro: Deve inserir uma quantidade."
                                    value="#{administradorManager.linhaEncomendaAtual.quantidade}" >
                                </h:inputText>
                                <h:button id="Adicionar" 
                                    value="Adicionar"
                                    binding="#{administradorManager.componente}"
                                    outcome="#{administradorManager.alterarLinhaEncomenda}">
                                </h:button>
                            </p:panelGrid>
                        </p:outputPanel>
                    </h:form>
                </p:dialog>
            </ui:define>
        </ui:composition>

    </h:body>
</html>

